#!/usr/bin/env python

import time
from uuid import uuid4
from sqlalchemy import String, Integer
from sqlalchemy import Column
from sqlalchemy.ext.declarative import declarative_base
from core.db import Base


from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel
from sqlalchemy import Boolean, Column, DateTime, Integer, String, event, ForeignKey
from sqlalchemy.ext.declarative import declared_attr


# SQLAlchemy models...
class TimeStampMixin(object):
    """ Timestamping mixin"""

    add_time = Column(DateTime, default=datetime.now)
    add_time._creation_order = 9998
    upd_time = Column(DateTime, default=datetime.now)
    upd_time._creation_order = 9998

    @staticmethod
    def _updated_at(mapper, connection, target):
        target.upd_time = datetime.now()

    @classmethod
    def __declare_last__(cls):
        event.listen(cls, "before_update", cls._updated_at)


class SaBaseModel(Base):
    id = Column(Integer, primary_key=True, doc='ID自动增长列')
    show_id = Column(String(64),default='',doc='展示ID')

BaseDO = declarative_base(cls=SaBaseModel)
metadata = BaseDO.metadata